{% extends 'blog/base.html' %}

{% block title %}
搜索
{% endblock %}

{% block content %}
{% if query %}
    <h1>包含 {{ query }}</h1>
    <h3>
    {% with results.count as total_results %}
       找到 {{ total_results }} 个结果
       {#  {{ total_results|pluralize }} 负数#}
    {% endwith %}
    </h3>
    {% for post in results %}
        <h4>
            <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
        </h4>
        {{ post.body|truncatewords:5 }}
    {% empty %}
        <p>啥都冒得</p>
    {% endfor %}
    <p><a href="{% url 'blog:post_search' %}">再搜一次</a></p>
    {% else %}
    <h1>搜索发布</h1>
    <form action="." method="get">
        {{ form.as_p }}
        <input type="submit" value="确认">
    </form>
{% endif %}
{% endblock %}